package gestionBulletins.controller;

import gestionBulletins.view.ConsultWindow;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPopupMenu;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;

/**
 * MouseListener qui permet de gérer le clic-droit pour le menu contextuel sur un adhérent.
 * @author Paraita Wohler
 *
 */
public class TableAdherentsMouseAdapter extends MouseAdapter {
	
	protected ConsultWindow target;
	protected JPopupMenu menu;
	
	/**
	 * Constructeur
	 * @param target la vue apellante
	 * @param menu le menu contextuel qu'on veut afficher
	 */
	public TableAdherentsMouseAdapter(ConsultWindow target,JPopupMenu menu) {
		this.target = target;
		this.menu = menu;
	}
	
	public void mouseClicked(MouseEvent e) {
		if (SwingUtilities.isLeftMouseButton(e)) {
			/* rien a faire, on selectionne juste */
		}
		else if (SwingUtilities.isRightMouseButton(e)){
			ListSelectionModel sm = target.table.getSelectionModel();
			int rowNum = target.table.rowAtPoint(e.getPoint());
			sm.setSelectionInterval(rowNum, rowNum);
			menu.show(e.getComponent(), e.getX(), e.getY());
			menu.setVisible(true);
			//infos.addActionListener(new TableAdherentsActionListener(target));
		}
	}
}
